<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\UserUploadDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateUserUploadRequest;
use App\Http\Requests\UpdateUserUploadRequest;
use App\Repositories\UserUploadRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class UserUploadController extends AppBaseController
{
    /** @var  UserUploadRepository */
    private $userUploadRepository;

    public function __construct(UserUploadRepository $userUploadRepo)
    {
        $this->userUploadRepository = $userUploadRepo;
    }

    /**
     * Display a listing of the UserUpload.
     *
     * @param UserUploadDataTable $userUploadDataTable
     * @return Response
     */
    public function index(UserUploadDataTable $userUploadDataTable)
    {
        return $userUploadDataTable->render('backend.user_uploads.index');
    }

    /**
     * Show the form for creating a new UserUpload.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.user_uploads.create');
    }

    /**
     * Store a newly created UserUpload in storage.
     *
     * @param CreateUserUploadRequest $request
     *
     * @return Response
     */
    public function store(CreateUserUploadRequest $request)
    {
        $input = $request->all();

        $userUpload = $this->userUploadRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'User Upload']));

        return redirect(route('userUploads.index'));
    }

    /**
     * Display the specified UserUpload.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $userUpload = $this->userUploadRepository->findWithoutFail($id);

        if (empty($userUpload)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'User Upload']));

            return redirect(route('userUploads.index'));
        }

        return view('backend.user_uploads.show')->with('userUpload', $userUpload);
    }

    /**
     * Show the form for editing the specified UserUpload.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $userUpload = $this->userUploadRepository->findWithoutFail($id);

        if (empty($userUpload)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'User Upload']));

            return redirect(route('userUploads.index'));
        }

        return view('backend.user_uploads.edit')->with('userUpload', $userUpload);
    }

    /**
     * Update the specified UserUpload in storage.
     *
     * @param  int              $id
     * @param UpdateUserUploadRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateUserUploadRequest $request)
    {
        $userUpload = $this->userUploadRepository->findWithoutFail($id);

        if (empty($userUpload)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'User Upload']));

            return redirect(route('userUploads.index'));
        }

        $userUpload = $this->userUploadRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'User Upload']));

        return redirect(route('userUploads.index'));
    }

    /**
     * Remove the specified UserUpload from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $userUpload = $this->userUploadRepository->findWithoutFail($id);

        if (empty($userUpload)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'User Upload']));

            return redirect(route('userUploads.index'));
        }

        $this->userUploadRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'User Upload']));

        return redirect(route('userUploads.index'));
    }
}
